package com.huas.controller;
import com.huas.common.Result;
import com.huas.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 阿里云OSS文件上传
 */
@RestController
@Slf4j
@RequestMapping("/system")
public class UploadController {

    @Resource
    private AliOssUtil aliOssUtil;

    @PostMapping("/upload")
    @PreAuthorize("hasAuthority('system:upload')")
    public Result<String> upload(MultipartFile file){
        log.info("文件上传：{}",file);
        String url = aliOssUtil.upload(file);
        return Result.success(url);
    }
}
